<?php
class ProfesoresController extends AppController {

	var $name = 'Profesores';

	function beforeFilter() {
		parent::beforeFilter();
		$this -> Auth -> allowedActions = array('*');
	}
	

	function index() {
		// $this->Profesor->recursive = 0;
		// $this->set('profesores', $this->paginate());
		$profesor = $this -> Profesor -> findByUsuarioId($this -> Auth -> user('id'));
		$this->set('profesor', $profesor);
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid profesor', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('profesor', $this->Profesor->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Profesor->create();
			if ($this->Profesor->save($this->data)) {
				$this->Session->setFlash(__('The profesor has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The profesor could not be saved. Please, try again.', true));
			}
		}
		$usuarios = $this->Profesor->Usuario->find('list');
		$this->set(compact('usuarios'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid profesor', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Profesor->save($this->data)) {
				$this->Session->setFlash(__('The profesor has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The profesor could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Profesor->read(null, $id);
		}
		$usuarios = $this->Profesor->Usuario->find('list');
		$this->set(compact('usuarios'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for profesor', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Profesor->delete($id)) {
			$this->Session->setFlash(__('Profesor deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Profesor was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>